<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>选择部门</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" type="text/css" href="assets/layui/css/layui.css"/>
		<link rel="stylesheet" href="assets/zTree/css/zTreeStyle.css" type="text/css">
		<style>
			ul.ztree li span.button.switch{margin-right:5px}
		    ul.ztree>li{padding: 8px;}
		    ul.ztree>li ul li{margin-top: 8px;padding: 5px;}
		    ul.ztree>li ul li ul li{background: #f6fbff;padding: 5px;}
		    ul.ztree>li ul li ul li ul li{background: #fff;padding: 5px;}
		    ul.ztree ul ul ul li{display:inline-block;}
		    ul.ztree>ul li>ul>li{padding:5px}
		    ul.ztree>ul li>ul{margin-top:12px}
		    ul.ztree>ul li{padding:15px;padding-right:25px}
		    ul.ztree>ul li{white-space:normal!important;background: #01AAED}
		    ul.ztree li{white-space:inherit;}
		    ul.ztree>li>a>span{font-size:14px;font-weight:700}
		</style>
	</head
	<body>
		<div class="layui-fluid" >
			<ul id="treeDemo" class="ztree"></ul>
		</div>
		<!--<div style="text-align: center;margin:20px auto;">
	        <button class="layui-btn sureBtn" lay-submit lay-filter="submit-btn">确   定</button>
	    </div>-->
		<script type="text/javascript" src="assets/js/jquery-1.8.1.min.js"></script>
		<script src="assets/layui/layui.js"></script>
		<script type="text/javascript" src="assets/zTree/js/jquery.ztree.core.min.js"></script>
		<script type="text/javascript" src="assets/zTree/js/jquery.ztree.excheck.min.js"></script>
		<script type="text/javascript">
		    var setting = {
		        check:{enable: false},
		        view: {showLine: true, showIcon: true, dblClickExpand: true },
		        data: {
		            simpleData: {enable: false, pIdKey:'pid', idKey:'id'},
		            key:{name:'name',children:'children'}
		        }
		    };
		    //var zNodes = {$data};
		    var zNodes = [
				{ "id":1,"pid":0,"name":"总公司",
					children: [
					{ "id":3, "name":"山西分公司"},
					{ "id":4, "name":"河北分公司"},
					{ "id":5, "name":"河南分公司"}
					]
				},
			];
		    function setCheck() {
		        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		        zTree.setting.check.chkboxType = { "Y":"ps", "N":"ps"};
		
		    };
		    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
		    setCheck();

		    function getVal(){
		    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		    	var theVal = $(".ztree li ul .curSelectedNode").attr("title");
		    	return theVal
		    }
		   

//		    layui.use(['form', 'layer'], function () {
//		        var form = layui.form, layer = layui.layer;
//		        form.on('submit(submit-btn)', function () {
//		            loading =layer.load(1, {shade: [0.1,'#fff']});
//		            // 提交到方法 默认为本身
//		            var treeObj=$.fn.zTree.getZTreeObj("treeDemo"),
//		                nodes=treeObj.getCheckedNodes(true),
//		                v="";
//		            for(var i=0;i<nodes.length;i++){
//		                v+=nodes[i].id + ",";
//		            }
//		            var id = "{:input('id')}";
//		            var user_name1  = $("[name='user_name']").val();
//		            var password1   = $("[name='password']").val();
//		            var repassword1 = $("[name='repassword']").val();
//		            var province1   = $("[name='province']").val();
//		            var city1       = $("[name='city']").val();
//		            var county1     = $("[name='county']").val();
//		            var branch      = $("[name='branch']").val();
//		
//		            $.post("{:url('editManager')}", {'rules':v,'id':id,'user_name':user_name1,'password':password1,'repassword':repassword1,'province':province1,'city':city1,'county':county1,'branch':branch}, function (res) {
//		                layer.close(loading);
//		                if (res.code == 0) {
//		                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
//		                    	var index = parent.layer.getFrameIndex(window.name);
//		                    	parent.layer.close(index);
//		                    	window.parent.location.reload();
//		                        //parent.location.href = res.url;
//		                    });
//		                } else {
//		                    layer.msg(res.msg, {time: 1800, icon: 0});
//		                }
//		            });
//		        })
//		
//		        var url =  "{:url('ajax/getArea')}"; //数据请求地址
//		        var province = ""; //编辑需要的省
//		        var city = ""; //编辑需要的市
//		        var county = ""; //编辑需要的县/区
//		//        getJSON(url,$("select[name='province']").closest("div"));
//		        form.on('select(state)', function(data){
//		            $that = $(data.elem);
//		            urls = url+"?id="+data.value;
//		            getJSON(urls,$that.closest("div").next());
//		        });
//		        function getJSON(urls,even){
//		            $.getJSON(urls, function(json){
//		                var pid = 0;
//		                var name = even.find("select").attr("name");
//		                var select = "<select name=\"" + name + "\" lay-filter=\"state\">";
//		                select += "<option value=\"0\">请选择 </option>";
//		                $(json).each(function(){
//		                    select += "<option value=\"" + this.id + "\"";
//		                    if(province == this.value || city == this.value || county == this.value){
//		                        select += " selected=\"selected\" ";
//		                        pid = this.id;
//		                    }
//		                    select += ">" + this.value + "</option>";
//		                });
//		                select += "</select>";
//		                even.html(select);
//		                var nextName = even.next().find("select").attr("name");
//		                even.next().html("<select name=\"" + nextName + "\" lay-filter=\"state\"><option value=\"0\">请选择 </option></select>");
//		                form.render('select');
//		            });
//		        }
//		    });
		</script>
	</body>

</html>